package com.yomahub.liteflow.example.controller;


import com.yomahub.liteflow.example.component.*;
import com.yomahub.liteflow.example.engine.FlowChain;
import com.yomahub.liteflow.example.engine.FlowChainService;
import com.yomahub.liteflow.example.slot.PriceContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component("priceCalApplyExtension")
public class PriceCalApplyExtension {


    FlowChain<PriceContext> applyFlowChain = null;

    @Autowired
    private FlowChainService flowChainService;

    @PostConstruct
    public void init() {
        applyFlowChain = FlowChain.newChain(flowChainService, PriceContext.class)
                .addNode(InitCmps.class)                //初始化价格步骤
                .addNode(PromotionConvertCmp.class)     //把商品包的优惠详细转换
                .addNode(MemberDiscountCmp.class)       //会员折扣计算组件
                .addNode(FullCutCmp.class)              //满减计算组件
                .addNode(FullDiscountCmp.class)         //满折计算组件
                .addNode(RushBuyCmp.class)              //抢购计算组件
                .addNode(CouponCmp.class)               //优惠券计算组件
                .addNode(PostageCmp.class)              //国内邮费计算组件
                .addNode(OverseaPostageCmp.class)       //海外邮费计算组件
                .addNode(PriceResultCmp.class)          //价格结果计算组件
                .addNode(StepPrintCmp.class) ;          //价格结果日志打印

    }
    public void apply(PriceContext context) {
        flowChainService.execute(applyFlowChain, context);
    }

}
